<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>第一个只出现一次的字符</title>
</head>

<body>
  <script>
    var Char = function (s) {
      let map = new Map();
      // 1.统计每个字符出现的次数
      for (let i of s) {
        if (!map.has(i)) {
          map.set(i, 1)
        } else {
          map.set(i, map.get(i) + 1)
        }
      }
      // 2.返回出现次数为1的即可
      for (let i of s) {
        if (map.get(i) === 1) {
          return i
        }
      }
      return ' '
    };
    console.log(Char('aaccdeffb'));
  </script>
</body>

</html>